package com.dragon.reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * @author dragon
 * @version V1.0.0-RELEASE
 * @date 2019/6/8 15:33
 */
public class ClassUtil {

    /**
     * 打印类的名称,字段,方法
     *
     * @param obj
     * @return void
     * @author dragon
     * @date 2019/6/8 15:35
     * @version V1.0.0-RELEASE
     */
    public static void printClassMessage(Object obj) {
        int a = 10;
        Class c = obj.getClass();
        System.out.println("类的名称是:" + c.getName());
        Method[] methods = c.getMethods();
        for (int i = 0; i < methods.length; i++) {
            Class<?> returnType = methods[i].getReturnType();
            System.out.print(returnType.getName() + " ");
            System.out.print(methods[i].getName() + "(");
            Class<?>[] parameterTypes = methods[i].getParameterTypes();
            for (Class<?> parameterType : parameterTypes) {
                System.out.print(parameterType.getName() + ",");
            }
            System.out.println(")");
        }
    }

    public static void main(String[] args) {
        String s = "hello";
        printClassMessage(s);
    }
}
